<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/7
 * Time: 14:58
 */

namespace ServerApp\lib\process;


use Swoole\Process;
use Swoole\Server;

class SGlobal
{
    /**
     * @var Process
     */
    public $process = null;

    /**
     * @var Server
     */
    public $server = null;

    /**
     * @var integer
     */
    public $worker_id = null;

    public $child_process_pids = [];

    private function __construct()
    {
    }

    private static $instance = null;

    public static function getInstance(){
        if(self::$instance === null) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function getByCallBack(string $key, callable $cb) {
        if(!isset($GLOBALS[$key])) {
            $GLOBALS[$key] = $cb();
        }
        return $GLOBALS[$key];
    }
}